﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;

namespace ProjManagSolution.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class pmWebService
    {
        [OperationContract]
        public void DoWork()
        {
            // Add your operation implementation here
            return;
        }

        // Add more operations here and mark them with [OperationContract]
        [OperationContract]
        public List<user> GetUsers()
        {
            Models db = new Models();
            return db.getUsers();
        }

        [OperationContract]
        public List<user> GetUserBySearchString(string search)
        {
            Models db = new Models();
            return db.getUsers(search);
        }

        [OperationContract]
        public user GetUserDetails(int userID)
        {
            Models db = new Models();
            return db.getUserDetail(userID);
        }

        [OperationContract]
        public List<project> GetProjects()
        {
            Models db = new Models();
            return db.getProjects();
        }

        [OperationContract]
        public List<project> GetProjectsBySearchString(string search)
        {
            Models db = new Models();
            return db.getProjects(search);
        }

        [OperationContract]
        public List<project> GetProjectsByManager(int managerID)
        {
            Models db = new Models();
            return db.getProjectsByManager(managerID);
        }

        [OperationContract]
        public List<milestone> GetMilestones(int projectID)
        {
            Models db = new Models();
            return db.getMileStones(projectID);
        }

        [OperationContract]
        public void InsertUser(user newUser)
        {
            Models db = new Models();
            db.insertUser(newUser);
        }

        [OperationContract]
        public List<phase> GetPhases(int milestoneID)
        {
            Models db = new Models();
            return db.getPhases(milestoneID);
        }

        [OperationContract]
        public List<task> GetTasks(int phaseID)
        {
            Models db = new Models();
            return db.getTasks(phaseID);
        }

        [OperationContract]
        public bool GetUserDetailByAuth(string email, string pass)
        {
            Models db = new Models();
            user result = db.getUserDetailByAuth(email, pass);

            if (result.user_email == null)
                return false;
            else
                return true;
        }

        [OperationContract]
        public List<project> GetInvolvedProjects(int userID)
        {
            Models db = new Models();
            return db.getInvolvedProjects(userID);
        }

        [OperationContract]
        public void UpdateUserDetails(int userID, user updatedUser)
        {
            Models db = new Models();
            db.updateUserDetail(userID, updatedUser);
        }

        [OperationContract]
        public void InsertProject(project newProject)
        {
            Models db = new Models();
            db.insertProject(newProject);
        }

        [OperationContract]
        public project GetProjectDetail(int projectID)
        {
            Models db = new Models();
            return db.getProjectDetail(projectID);
        }

        [OperationContract]
        public void UpdateProjectDetails(int projectID, project updatedProject)
        {
            Models db = new Models();
            db.updateProjectDetail(projectID, updatedProject);
        }

        [OperationContract]
        public void DeleteProject(int projectID)
        {
            Models db = new Models();
            db.deleteProject(projectID);
        }

        [OperationContract]
        public List<user> GetProjectMembers(int projectID)
        {
            Models db = new Models();
            return db.getProjectMembers(projectID);
        }

        [OperationContract]
        public user GetUserDetailByEmail(string email)
        {
            Models db = new Models();
            return db.getUserDetailByEmail(email);
        }

        [OperationContract]
        public void InsertDocumentation(int uploaderID, int projectID, string documentationName, string url, DateTime date, string status)
        {
            Models db = new Models();
            db.insertDocumentation(uploaderID , projectID , documentationName ,url ,date , status);
        }

        [OperationContract]
        public void InsertFolder(int projectID)
        {
            Models db = new Models();
            db.insertFolder(projectID);
        }

        [OperationContract]
        public void InsertMileStone(int projectid , string mname , string mdesc , DateTime start , DateTime end)
        {
            Models db = new Models();
            db.insertMileStone(projectid, mname , mdesc , start , end);
        }

        [OperationContract]
        public void InsertPhase(int mid, string pname, string pdesc, DateTime start, DateTime end)
        {
            Models db = new Models();
            db.insertPhase(mid , pname , pdesc , start , end);
        }

        [OperationContract]
        public void InsertTask(int pid, string taskname, string taskdesc, DateTime start, DateTime end, string report, int complete)
        {
            Models db = new Models();
            db.insertTask(pid , taskname , taskdesc , start , end , report , complete);
        }

        [OperationContract]
        public void DeleteDocmentation(int documentID)
        {
            Models db = new Models();
            db.deleteDocumentation(documentID);
        }

        [OperationContract]
        public void DeleteFolder(int folderID)
        {
            Models db = new Models();
            db.deleteFolder(folderID);
        }

        [OperationContract]
        public void DeleteMilestone(int milestoneID)
        {
            Models db = new Models();
            db.deleteMilestone(milestoneID);
        }

        [OperationContract]
        public void DeletePhase(int phaseID)
        {
            Models db = new Models();
            db.deletePhase(phaseID);
        }

        [OperationContract]
        public List<folder> GetFolders(int projectID)
        {
            Models db = new Models();
            return db.getFolders(projectID);
        }

        [OperationContract]
        public task GetTaskDetail(int taskID)
        {
            Models db = new Models();
            return db.getTaskDetail(taskID);
        }

        [OperationContract]
        public void InviteUser(int userID, int projectID, string role)
        {
            Models db = new Models();
            db.inviteUser(userID, projectID, role);
        }

        [OperationContract]
        public void ReAssignMemberRole(int userID, int projectID, string role)
        {
            Models db = new Models();
            db.reassignMemberRole(userID, projectID, role);
        }

        [OperationContract]
        public void RejectMember(int userID, int projectID)
        {
            Models db = new Models();
            db.rejectMember(userID, projectID);
        }

        [OperationContract]
        public void UpdateFolderDetail(int folderID , folder updatedFolder)
        {
            Models db = new Models();
            db.updateFolderDetail(folderID, updatedFolder);
        }

        [OperationContract]
        public void UpdateMilestoneDetail(int milestoneID, milestone updatedMilestone)
        {
            Models db = new Models();
            db.updateMilestoneDetail(milestoneID, updatedMilestone);
        }

        [OperationContract]
        public void UpdatePhaseDetail(int phaseID, phase updatedPhase)
        {
            Models db = new Models();
            db.updatePhaseDetail(phaseID, updatedPhase);
        }

        [OperationContract]
        public void UpdateTaskDetail(int taskID, task updatedTask)
        {
            Models db = new Models();
            db.updateTaskDetail(taskID, updatedTask);
        }

        [OperationContract]
        public string GetRoleByUser(int userid, int projectid)
        {
            Models db = new Models();
            return db.getUserRole(userid, projectid);
        }

        [OperationContract]
        public void InsertProjectNew(int managerid, string projectname, string projectdes, DateTime start, DateTime end)
        {
            Models db = new Models();
            db.insertProjectNew(managerid, projectname, projectdes, start, end);
        }
    }
}
